package study.apple;

import org.omg.CORBA.Object;

import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.util.HashMap;
import java.util.Map;

import static java.util.Comparator.comparingLong;
import static java.util.stream.Collectors.collectingAndThen;

public class AppleApplication {
    public static void  main(String[] args){
      Apple apple=new Apple(1,"huan",new BigDecimal(10),10);
        System.out.println(apple.hashCode());
        System.out.println(apple.getId());
        apple.setId(3);
        System.out.println(apple.getId());
         List<Apple> appleList = new ArrayList<>();//存放apple对象集合

    Apple apple1 =  new Apple(1,"苹果1",new BigDecimal("3.25"),10);
    Apple apple12 = new Apple(1,"苹果2",new BigDecimal("1.35"),20);
    Apple apple2 =  new Apple(2,"香蕉",new BigDecimal("2.89"),30);
    Apple apple3 =  new Apple(3,"荔枝",new BigDecimal("9.99"),40);

        appleList.add(apple1);
        appleList.add(apple12);
        appleList.add(apple2);
        appleList.add(apple3);
        System.out.println(appleList);
        Map<Integer, List<Apple>> groupBy = appleList.stream().collect(Collectors.groupingBy(Apple::getId));
        System.err.println("groupBy:"+groupBy);
       System.out.println(groupBy.size());
        Map<Integer, Apple> appleMap = appleList.stream().collect(Collectors.toMap(Apple::getId, a -> a,(k1,k2)->k1));
        System.out.println(appleMap);
        List<Apple> filterList = appleList.stream().filter(a -> a.getName().equals("香蕉")).collect(Collectors.toList());
        System.err.println("filterList:"+filterList);
        BigDecimal totalMoney = appleList.stream().map(Apple::getMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
        System.err.println("totalMoney:"+totalMoney);
        /*Optional<Dish> maxDish = Dish.menu.stream().
                collect(Collectors.maxBy(Comparator.comparing(Dish::getCalories)));
        maxDish.ifPresent(System.out::println);

        Optional<Dish> minDish = Dish.menu.stream().
                collect(Collectors.minBy(Comparator.comparing(Dish::getCalories)));
        minDish.ifPresent(System.out::println);
        List<Person> unique = appleList.stream().collect(
                collectingAndThen(
                        toCollection(() -> new TreeSet<>(comparingLong(Apple::getId))), ArrayList::new)
        );*/
        Map<String, String> m1 = new HashMap<>();
        m1.put("Zara", "8");
        m1.put("Mahnaz", "31");
        m1.put("Ayan", "12");
        m1.put("Daisy", "14");
        System.out.println(m1.get("Zara"));
        //Object obj = new Object();

    }
}
